<template>
  <view class="order_detail">
    <!-- #ifndef MP-WEIXIN -->
    <my-navbar
      leftText="订单详情"
      :height="100"
      :background="'#ffffff'"
      @leftClick="leftClick"
    ></my-navbar>
    <!-- #endif -->

    <view class="order_info">
      <view class="pay">
        <view>
          <text class="title">订单信息</text>
          <!-- <text class="red_font" v-if="orderInfo.pay_status==0">未支付</text> -->
          <text class="dgreen" v-if="orderInfo.order_status == 0">待审核</text>
          <text class="dgreen" v-else-if="orderInfo.order_status == 1"
            >备货中</text
          >
          <text class="dgreen" v-else-if="orderInfo.order_status == 2"
            >配送中</text
          >
          <text class="dgreen" v-else-if="orderInfo.order_status == 3"
            >已收货</text
          >
          <text class="gray_font" v-else-if="orderInfo.order_status == 4"
            >已取消</text
          >
        </view>
        <view
          ><text>下单时间</text><text>{{ orderInfo.createdTime }}</text></view
        >
        <view
          ><text>配送日期</text><text>{{ orderInfo.send_time }}</text></view
        >
        <view v-if="orderInfo.send_time_id == 0"
          ><text>配送时间</text><text>不限</text></view
        >
        <view v-else
          ><text>配送时间</text><text>{{ startTime }}~{{ endTime }}</text></view
        >
        <view
          ><text>订单编号</text><text>{{ orderInfo.order_sn }}</text></view
        >
        <view
          ><text>收货人</text><text>{{ orderInfo.contact }}</text></view
        >
        <view
          ><text>联系电话</text><text>{{ orderInfo.mobile }}</text></view
        >
        <view
          ><text class="prop">收货地址</text
          ><text>{{ orderInfo.address }}</text></view
        >
        <view
          ><text class="prop">配送金额</text
          ><text
            >￥{{
              orderInfo.order_status == 2 || orderInfo.order_status == 3
                ? orderInfo.send_money
                : "0.00"
            }}</text
          >
        </view>
        <view
          ><text class="prop">退货金额</text
          ><text>￥{{ orderInfo.return_money }}</text></view
        >
        <view
          ><text class="prop">备注</text
          ><text>{{ orderInfo.remark }}</text></view
        >
      </view>
      <view class="money">
        <view class="flex-btw">
          <text class="title">支付信息</text>
          <text>{{ orderInfo.pay_status == 0 ? "未支付" : "已支付" }}</text>
        </view>
        <view
          ><text>商品总金额</text
          ><text class="red_font">￥{{ orderInfo.order_money }}</text></view
        >
        <view
          ><text>满减</text
          ><text class="gray_font"
            >￥{{ orderInfo.full_reduction_money }}</text
          ></view
        >
        <view
          ><text>优惠券</text
          ><text class="gray_font">￥{{ orderInfo.discount_money }}</text></view
        >
        <view
          ><text>运费</text
          ><text class="gray_font">￥{{ orderInfo.delivery_fee }}</text></view
        >
        <view
          ><text>下单金额</text
          ><text class="gray_font">￥{{ orderInfo.should_money }}</text></view
        >
        <view
          ><text>差额</text
          ><text class="gray_font">￥{{ orderInfo.balance }}</text></view
        >
        <view
          ><text>实付金额</text
          ><text class="red_font">￥{{ orderInfo.real_money }}</text></view
        >
        <view
          ><text>支付方式</text
          ><text class="gray_font">{{
            orderInfo.is_prior_payment == 1 ? "在线付款" : "货到付款"
          }}</text>
        </view>
        <view
          ><text>积分</text
          ><text class="gray_font">- {{ orderInfo.points }}</text></view
        >
      </view>
      <view v-if="settlement_info.length >= 1" class="money">
        <view class="flex-btw">
          <text class="title">结算记录</text>
        </view>
        <view v-for="settlement of settlement_info" :key="settlement.id">
          <text @click="toDetail(settlement.id)" class="line">{{
            settlement.order_sn
          }}</text>
          <text>￥{{ settlement.account_money }}</text>
        </view>
      </view>
      <view v-if="return_info.length >= 1" class="money">
        <view class="flex-btw">
          <text class="title">退货记录</text>
        </view>
        <view v-for="returns of return_info" :key="returns.id">
          <text @click="returninfo(returns.id)" class="line">{{
            returns.order_sn
          }}</text>
          <text>￥{{ returns.real_money }}</text>
        </view>
      </view>
      <view class="good_info">
        <view class="good_info_fff">
          <view class="title"> 商品信息 </view>
          <view
            class="sign_good"
            v-for="(item, index) in goodsList"
            :key="index"
          >
            <view class="flex-middle top">
              <view class="imgs flex-middle">
                <img class="img" :src="item.img" mode="aspectFit" alt="" />
              </view>
              <text class="name">{{ item.name }}</text>
              <text class="spu">{{ item.spu_name }}</text>
              <view class="yellow_tag" v-if="item.datum_activity">{{
                item.datum_activity
              }}</view>
            </view>
            <template v-if="item.datum_activity == '积分'">
              <view class="row">
                <text>兑换数量：{{ Number(item.order_num) }}</text>
                <text
                  >配送数量：{{
                    orderInfo.order_status == 2 || orderInfo.order_status == 3
                      ? Number(item.sort_num)
                      : 0
                  }}</text
                >
              </view>
              <view class="row">
                <text>兑换积分：{{ orderInfo.points }}</text>
                <text></text>
              </view>
            </template>
            <template v-else>
              <view class="row">
                <text>下单数量：{{ Number(item.order_num) }}</text>
                <text
                  >配送数量：{{
                    orderInfo.order_status == 2 || orderInfo.order_status == 3
                      ? Number(item.sort_num)
                      : 0
                  }}</text
                >
              </view>
              <view class="row">
                <text v-show="canshowprice"
                  >下单单价：￥{{ Number(item.order_price).toFixed(2) }}</text
                >
                <text v-show="canshowprice"
                  >配送单价：￥{{
                    orderInfo.order_status == 2 || orderInfo.order_status == 3
                      ? Number(item.sort_price).toFixed(2)
                      : "0.00"
                  }}</text
                >
              </view>
              <view class="row">
                <text v-show="canshowprice"
                  >下单金额：￥{{
                    Number(item.order_item_money).toFixed(2)
                  }}</text
                >
                <text
                  >配送金额：￥{{
                    orderInfo.order_status == 2 || orderInfo.order_status == 3
                      ? Number(item.sort_money).toFixed(2)
                      : "0.00"
                  }}</text
                >
              </view>
            </template>
            <view
              >备注：<text class="note">{{ item.remark }}</text></view
            >
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
let app = getApp();
import { $https } from "@/static/js/request.js";
import MixinShowprice from "@/static/js/mixinshowprice.js";
export default {
  data() {
    return {
      logo: "",
      showLogo: 0,
      orderInfo: {}, //订单信息
      goodsList: [], //商品列表
      startTime: "",
      endTime: "",
      return_info: [],
      settlement_info: [],
      type: 0,
    };
  },
  mixins: [MixinShowprice],
  onReady() {
    getApp().setTitle();
  },
  onLoad(option) {
    this.getData(option.id);
    this.logo = uni.getStorageSync("logo");
    this.showLogo = uni.getStorageSync("showLogo");
  },
  onUnload() {
    // #ifdef MP-WEIXIN
    uni.$emit("updateorder", () => {});
    // #endif
  },
  methods: {
    getData(id) {
      $https(
        "GET",
        "getOrderDetail",
        {
          oid: id,
        },
        (res) => {
          this.type = res.data.data.order_info.is_prior_payment;
          console.log(this.type);
          this.return_info = res.data.data.return_info;
          this.settlement_info = res.data.data.settlement_info;
          var info = res.data.data.order_info;
          var ms = Number(info.created_at + "000");
          var now = new Date();
          now.setTime(ms);
          var date =
            now.getFullYear() +
            "-" +
            (now.getMonth() + 1) +
            "-" +
            now.getDate() +
            " " +
            now.getHours() +
            ":" +
            now.getMinutes() +
            ":" +
            now.getSeconds();
          info.createdTime = date;
          this.orderInfo = info;
          this.startTime = info.send_time_period.start_time;
          this.endTime = info.send_time_period.end_time;
          this.goodsList = res.data.data.goods_info;
        }
      );
    },
    leftClick() {
      uni.$emit("updateorder", {
        id: app.globalData.tabIndex,
      });
      // #ifdef H5
      window.history.back(-1);
      // #endif
      // #ifndef H5
      uni.navigateBack();
      // #endif
    },
    toDetail(id) {
      let type = this.type == 0 ? 2 : 1;
      uni.navigateTo({
        url: `/pages/user/final_statement/final_statement_detail?id=${id}&type=${type}`,
      });
    },
    returninfo(id) {
      uni.navigateTo({
        url: `/pages/user/return_goods/return_goods_detail?id=${id}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.order_info {
  background-color: #f6f6f6;

  .prop {
    white-space: nowrap;
    margin-right: 20rpx;
  }

  .pay > view,
  .money > view {
    margin-top: 20rpx;
  }

  .gray_font {
    color: gray;
  }
}

.order_detail {
  .pay > view,
  .money > view {
    display: flex;
    justify-content: space-between;
  }

  .pay,
  .money {
    background-color: #fff;
    border-bottom: 1px solid #e8e9e9;
    padding: 10rpx 30rpx 18rpx;
    margin-bottom: 10rpx;
  }

  .pay > view:nth-child(n + 2) text:last-child {
    color: gray;
  }

  .good_info {
    padding-top: 25rpx;
  }

  .title {
    font-size: 18rpx;
    font-weight: bold;
  }

  text {
    font-size: 18rpx;
  }
}

.good_info {
  padding: 0 30rpx 30rpx;
  background-color: #fff;

  .good_info_fff {
    background-color: #f6f6f6;
    padding-bottom: 30rpx;
    border-radius: 14rpx;
  }

  .title {
    height: 60rpx;
    line-height: 60rpx;
    margin-left: 20rpx;
  }

  .sign_good {
    width: 640rpx;
    font-size: 24rpx;
    background: #fff;
    border-radius: 14rpx;
    margin: 0 auto;
    padding: 20rpx;

    + .sign_good {
      margin-top: 20rpx;
    }

    .yellow_tag {
      font-size: 20rpx;
      padding: 2rpx 12rpx;
      background: #ff9900;
      border-radius: 6rpx;
      color: #fff;
      margin-left: 8rpx;
    }

    .top {
      margin-bottom: 20rpx;

      .imgs {
        width: 120rpx;
        height: 120rpx;
        position: relative;

        .logo {
          width: 40rpx;
          height: 40rpx;
          position: absolute;
          top: 0;
          left: 0;
          z-index: 1;
        }

        .img {
          width: 120rpx;
          max-height: 100rpx;
          margin-right: 40rpx;
        }
      }

      .name {
        margin-left: 20rpx;
      }
    }

    .row {
      margin-bottom: 20rpx;

      text:first-child {
        display: inline-block;
        width: 60%;
      }
    }

    .note {
      color: #9a9a9a;
      white-space: normal;
      word-break: break-all;
    }

    .spu {
      margin-left: 20rpx;
      padding: 4rpx 8rpx;
      background: #f5f5f5;
      border-radius: 8rpx;
      font-size: 24rpx;
      transform: scale(0.8);
    }
  }
}

.line {
  color: #0f0acb;
  text-decoration: underline;
}
.fonts {
  font-family: PingFang SC;
  font-weight: bold;
  color: #333333;
}
</style>
